from sqlalchemy import Column, Integer, String, Boolean, DateTime, func

from project.database import Base


class BaseModelInDB:
    """
    公共字段类
    """
    id = Column(Integer, primary_key=True, autoincrement=True, comment="id")
    created_at = Column(DateTime(6), server_default=func.now(), comment='创建时间')
    updated_at = Column(DateTime(6), server_default=func.now(), onupdate=func.now(), comment='更新时间')


class UserInDB(Base, BaseModelInDB):
    """
    用户表
    """
    __tablename__ = "user"
    username = Column(String(50), unique=True, index=True, nullable=False, comment="用户名")
    password = Column(String(100), nullable=False, comment="hash后的密码")
    state = Column(Boolean, default=True, comment="账户状态")
